package com.rongdu.workflow.controller;

import java.util.List;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/ProcessDefinitionAction")
public class ProcessDefinitionAction {

	@Autowired
	private RepositoryService repositoryService;
	
	@RequestMapping("deploy.do")
	public void deploy() {
		String resource = "bpm/permission.bpmn20.xml";
		repositoryService.createDeployment().addClasspathResource(resource).deploy();
	}
	
	@RequestMapping("queryAllDeployedProcessDefinitions.do")
	public String queryAllDeployedProcessDefinitions(Model model) {
		ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
		List<ProcessDefinition> processDefinitions = processDefinitionQuery.list();
		model.addAttribute("processDefinitions", processDefinitions);
		
		return "processDefinitionDisplay";
	}
	
	@RequestMapping("ping.do")
	public String ping (){
		return "hello";
	}
}
